package com.tgy.admin.Service.impl;

import com.tgy.admin.Service.AdminCommentService;
import com.tgy.admin.util.BeanFieldUtils;
import com.tgy.core.service.BlogCommentService;
import com.tgy.page.PageQuery;
import com.tgy.pojo.BlogComment;
import com.tgy.result.GraceJSONResult;
import com.tgy.result.LayuiTableResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tianguiyin
 * @version 1.0
 * @date 2022/6/21 21:04
 *
 * 后台用户业务实现
 */
@Service
public class AdminCommentServiceImpl implements AdminCommentService {

    @Resource
    private BlogCommentService blogCommentService;
    @Resource
    private BeanFieldUtils beanFieldUtils;


    @Override
    public LayuiTableResult getBlogCommentList(BlogComment bo, PageQuery pageQuery) {
        return blogCommentService.queryLayuiPageList(bo, pageQuery);
    }


    @Override
    public GraceJSONResult addBlogComment(BlogComment bo) {
        try {
            beanFieldUtils.add(bo);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return GraceJSONResult.ok(blogCommentService.insertByBo(bo));
    }

    @Override
    public GraceJSONResult updateBlogComment(BlogComment bo) {
        try {
            beanFieldUtils.update(bo);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return GraceJSONResult.ok(blogCommentService.updateByBo(bo));
    }

    @Override
    public GraceJSONResult delBlogComment(String id) {
        return GraceJSONResult.ok(blogCommentService.deleteById(id));
    }

    @Override
    public GraceJSONResult delBlogCommentIds(List<String> ids) {
        return GraceJSONResult.ok(blogCommentService.deleteWithValidByIds(ids, false));
    }

    @Override
    public GraceJSONResult getBlogCommentById(String id) {
        return GraceJSONResult.ok(blogCommentService.queryById(id));
    }

    @Override
    public LayuiTableResult getAllSysRoleList(String userId, PageQuery pageQuery) {
        return null;
    }

    @Override
    public GraceJSONResult updateStatus(String id, Integer status) {
        int i = blogCommentService.updateStatus(id,status);
        if (i>0){
            return GraceJSONResult.ok();
        }else {
            return GraceJSONResult.error();
        }
    }

}
